/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConsultarCuenta.java
 *
 * Created on 27-feb-2012, 2:07:37
 */
package view;

import entity.Cuenta;
import entity.Movimiento;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import service.EurekaService;

/**
 *
 * @author AnDerSon
 */
public class ConsultarCuenta extends javax.swing.JInternalFrame {

    private static ConsultarCuenta instancia = null;

    static {
        instancia = new ConsultarCuenta();
    }

    public static ConsultarCuenta getInstancia() {
        return instancia;
    }

    /** Creates new form ConsultarCuenta */
    public ConsultarCuenta() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtCuenta = new javax.swing.JTextField();
        txtTitular = new javax.swing.JTextField();
        txtMoneda = new javax.swing.JTextField();
        txtSaldo = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabMovimiento = new javax.swing.JTable();
        btnConsulta = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setClosable(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel1.setForeground(new java.awt.Color(0, 102, 255));
        jLabel1.setText("Consultar de Cuenta");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, -1, -1));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setForeground(new java.awt.Color(0, 102, 255));
        jLabel2.setText("CUENTA");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 60, -1, -1));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setForeground(new java.awt.Color(0, 102, 255));
        jLabel3.setText("TITULAR");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 100, -1, -1));

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setForeground(new java.awt.Color(0, 102, 255));
        jLabel4.setText("MONEDA");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 140, -1, -1));

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel5.setForeground(new java.awt.Color(0, 102, 255));
        jLabel5.setText("SALDO");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 180, -1, -1));
        getContentPane().add(txtCuenta, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 60, 80, -1));

        txtTitular.setEditable(false);
        getContentPane().add(txtTitular, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 100, 220, -1));

        txtMoneda.setEditable(false);
        getContentPane().add(txtMoneda, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 140, 60, -1));

        txtSaldo.setEditable(false);
        getContentPane().add(txtSaldo, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 180, 60, -1));

        tabMovimiento.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Nro. Mov.", "Tipo de Movimiento", "Fecha", "Importe"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tabMovimiento);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 220, -1, 160));

        btnConsulta.setFont(new java.awt.Font("Tahoma", 0, 14));
        btnConsulta.setForeground(new java.awt.Color(0, 102, 255));
        btnConsulta.setText("Consultar");
        btnConsulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultaActionPerformed(evt);
            }
        });
        getContentPane().add(btnConsulta, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 50, 120, 30));

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 100, -1, -1));

        jButton2.setText("jButton2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 150, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnConsultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultaActionPerformed

        // Limpiando la tabla
		DefaultTableModel model = (DefaultTableModel) tabMovimiento.getModel();
		model.setNumRows(0);

        Cuenta cuenta = new Cuenta();
        cuenta.setCodigo(txtCuenta.getText());

     EurekaService es = new EurekaService();

     
            
            List<Movimiento> movimientos = es.consultaMovimientos(cuenta.getCodigo().trim());
            for (Movimiento mov : movimientos) {
                model.addRow(mov.toArray());
            }
       




    }//GEN-LAST:event_btnConsultaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        
        Cuenta cuenta = new Cuenta();
        cuenta.setCodigo(txtCuenta.getText());

        
         EurekaService es = new EurekaService();

        
          String nombre = es.consultaCliente(cuenta.getCodigo());
        txtTitular.setText(nombre);

        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        
        
            Cuenta cuenta = new Cuenta();
        cuenta.setCodigo(txtCuenta.getText());

        
         EurekaService es = new EurekaService();
        
        List<Cuenta> cs = es.datosCuenta(cuenta);
        System.out.println(cs.get(0).getSaldo() + "");
        System.out.println(cs.get(0).getCodMoneda() + "");
        
      
        if( cs.get(0).getCodMoneda().equals("01"))
        
            txtMoneda.setText("Soles");
        else
             txtMoneda.setText("Dolares");
        
        
        txtSaldo.setText(String.valueOf(cs.get(0).getSaldo()));

    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConsulta;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabMovimiento;
    private javax.swing.JTextField txtCuenta;
    private javax.swing.JTextField txtMoneda;
    private javax.swing.JTextField txtSaldo;
    private javax.swing.JTextField txtTitular;
    // End of variables declaration//GEN-END:variables
}
